// 云函数入口文件
const cloud = require('wx-server-sdk')
const request=require('request')
cloud.init()
function getInfo(data){
     return new Promise((resolve,reject)=>{
       request(data,(err,res,data)=>{
         if(err) reject(err);
         resolve(data)
       })
     })
}
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let city=event.city;
  let type=event.type;
  let name =encodeURIComponent(event.name);
  console.log(name);
  let key ='HgeQWDFNR5FuoDW8IUt0YIZMNF92PFDT6ZdjvRHbBTMByhYwQVT0X5w15fZn5dO5'
  let opt={
    url:`http://api01.idataapi.cn:8000/house/goufangwang?type=${type}&cityid=${city}&kw=${name}&apikey=${key}`
  }
  return JSON.parse(await getInfo(opt));
}